package org.jash.ting13

import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import com.tencent.mmkv.MMKV
import kotlinx.coroutines.launch
import org.jash.ting13.net.APIService
import org.jash.ting13.user.LoginActivity
import org.jash.utils.log
import org.jash.utils.net.service
import java.net.URLDecoder
import java.nio.charset.StandardCharsets

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        lifecycleScope.launch {
            val service:APIService = service()
            val play = service.getPlay("/play/27208_1_182473.html")
//            val play = service.getPlay("/play/27208_1_151266.html")
            log(play)
            val url = service.getUrl(play.sc, play.sp, play.nid, play.cid, play.sort)
            log(url)
//            val kv = MMKV.mmkvWithID("ting13")
//            kv.allKeys()?.forEach {
//                log("$it: ${URLDecoder.decode(kv.decodeString(it), "UTF-8")}")
//            }
//            startActivity(Intent(this@MainActivity, LoginActivity::class.java))
        }


    }
}